package Object.UserManager;

import java.util.ArrayList;
import java.util.List;

public class UserManager {
    //User是声明这个集合中只能存储User类型的对象
    private final List<User> userDatabase = new ArrayList<>();
    public void initUser(int n){
        for (int i = 1; i <= n ; i++) {
            String userName ="user"+i;
            userDatabase.add(new User(userName));
        }
        printAllUsers();
    }
    public void printAllUsers(){
        System.out.println("数据库中的数据");
        for(User user:userDatabase){
            System.out.println(user);
        }
        System.out.println("--------------");
    }
    public boolean registerUser(String userName, String password){
        for (User user:userDatabase){
            if (user.getUserName().equals(userName)){
                return false;
            }
        }
        userDatabase.add(new User(userName,password));
        return true;
    }
    public boolean loginUser (String userName,String password){
        for (User user:userDatabase){
            if (user.getUserName().equals(userName)){
                return user.getPassword().equals(password);
            }
        }
        return false;
    }
}
